package com.example.controller;

import com.example.domain.property.Tag;
import com.example.domain.property.Type;
import com.example.service.TagService;
import com.example.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/tag")
public class TagController {
    @Autowired
    private TagService tagService;
    //分页查询
    @GetMapping("/list/{currentPage}/{PageSize}")
    @ResponseBody
    public Page<Tag> index1(@PathVariable(value = "currentPage")int currentPage, @PathVariable(value = "PageSize") int PageSize){
        Page<Tag> page = tagService.selectTypePage(currentPage, PageSize);
        return page;
    }
    //新增数据
    @PostMapping("/insert")
    @ResponseBody
    public Boolean index2(@RequestBody Tag tag){
        boolean flag = tagService.insert(tag);
        return flag;
    }
    //查询id
    @GetMapping("/selectId/{id}")
    @ResponseBody
    public Tag index3(@PathVariable(value = "id") Long id){
        Tag tag = tagService.selectOne(id);
        return tag;
    }
    //根据id更新数据
    @PutMapping("/updateRow")
    @ResponseBody
    public Boolean index4(@RequestBody Tag tag){
        boolean flag = tagService.updateById(tag);
        return flag;
    }
    //根据id删除数据
    @DeleteMapping("/deleteRow/{id}")
    @ResponseBody
    public Boolean index5(@PathVariable(value = "id") Long id){
        boolean flag = tagService.deleteById(id);
        return flag;
    }
    //查询所有标签
    @GetMapping("/findAll")
    @ResponseBody
    public List<Tag> index8(){
        List<Tag> list = tagService.findAll();
        return list;
    }
}
